using MemoryPack;
using Game.Networking.Client;

namespace Game.Networking {
	public sealed class S_InfoUpdateMessageHandler : BaseServerMessageHandler {
		public override ServerPacketID CommandId {
			get {
				return ServerPacketID.InfoUpdateEvent;
			}
		}

		public override void ProcessMessage(byte[] rawCommand) {
			var command = MemoryPackSerializer.Deserialize<S_InfoUpdateMessage>(rawCommand);
			using ( ByteStreamFormatter reader = new ByteStreamFormatter(command.EventArgs) ) {
				switch ( command.EventType ) {
					case InfoEventType.UnitStateChanged:
						var state = (ComputingUnitState) reader.Read_Byte();
						ClientScriptingController.Instance.SetUnitState(state);
						break;
					case InfoEventType.UnitAttachedEntityIdChanged:
						var id = reader.Read_Uint();
						ClientScriptingController.Instance.SetAttachedEntityId(id);
						break;
					case InfoEventType.None:
					default:
						break;
				}
			}
		}
	}
}
